package com.ityy.ruiji.dao;

import com.ityy.ruiji.entity.Dish;
import com.ityy.ruiji.entity.dto.DishDto;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface DishDao {


    @Select("SELECT COUNT(*) FROM dish WHERE category_id =#{id}")
    Long findCountByCategoryId(Long id);

    List<Dish> findByName(@Param("name") String name);

    //我们目标，该数据插入之后，该菜品是有一个主键的，我们希望这个主键重新封装回到实体类里面
    @Insert("insert into  dish values(null,#{name},#{categoryId},#{price},#{code},#{image},#{description},#{status},#{sort},#{createTime},#{updateTime},#{createUser},#{updateUser},0)")
    // useGeneratedKeys = true,keyColumn = ,keyProperty = ""  开启主键插入后自动封装，
    @Options(useGeneratedKeys = true,keyColumn ="id" ,keyProperty = "id")
    void insert(DishDto dishDto);

    @Select("select * from dish where id =#{id}")
    Dish findById(Long id);

    void update(DishDto dishDto);

    //这个方法已经有两个参数，一定要使@Param注解
    List<Dish> list(@Param("categoryId") Long categoryId,@Param("status") Integer status);
}
